package com.aweqy.hrmanager.controller;

import com.aweqy.hrmanager.entity.Consumption;
import com.aweqy.hrmanager.service.ConsumptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/consumptions")
@CrossOrigin(origins = "*")
public class ConsumptionController {

    @Autowired
    private ConsumptionService consumptionService;

    @GetMapping
    public List<Consumption> getAllConsumptions() {
        return consumptionService.list();
    }

    @PostMapping
    public boolean addConsumption(@RequestBody Consumption consumption) {
        return consumptionService.save(consumption);
    }

    @PutMapping
    public boolean updateConsumption(@RequestBody Consumption consumption) {
        return consumptionService.updateById(consumption);
    }

    @DeleteMapping("/{id}")
    public boolean deleteConsumption(@PathVariable Integer id) {
        return consumptionService.removeById(id);
    }
} 